# # coding=utf-8
# import sys
# from PyQt4 import  QtCore, QtGui
# class MyWindow( QtGui.QMainWindow ):
    # def __init__( self ):
        # QtGui.QMainWindow.__init__( self )
        # self.setWindowTitle( "PyQt" )
        # self.resize( 300, 200 )
# app = QtGui.QApplication( sys.argv )
# mywindow = MyWindow()
# mywindow.show()
# app.exec_()

# #coding=utf-8
# #标签的使用
# import sys
# from PyQt4 import QtCore, QtGui
# class Window( QtGui.QMainWindow ):
    # def __init__( self ):
        # super( Window, self ).__init__()
        # self.setWindowTitle( "hello" )
        # self.resize( 200, 300 )
        # #添加标签
        # label = QtGui.QLabel( "label" )
        # label.setAlignment( QtCore.Qt.AlignCenter )
        # self.setCentralWidget( label )
# app = QtGui.QApplication( sys.argv )
# demo = Window()
# demo.show()
# app.exec_()

# #coding=gbk
# import sys
# from PyQt4 import QtCore, QtGui
# class Window( QtGui.QWidget ):
    # def __init__( self ):
        # super( Window, self ).__init__()
        # self.setWindowTitle( "hello" )
        # self.resize( 500, 500 )
         
        # hBoxLayout1 = QtGui.QHBoxLayout()
         
        # label1 = QtGui.QLabel( "Label1" )
        # label2 = QtGui.QLabel( "Label2" )
        # label3 = QtGui.QLabel( "Label3" )
        # label4 = QtGui.QLabel( "Label4" )
        # label5 = QtGui.QLabel( "Label5" )
        # #---------添加表格布局
        # gridLayout = QtGui.QGridLayout()
          
        # gridLayout.addWidget( label1 , 0, 0 )
        # gridLayout.addWidget( label2 , 0, 1 )
        # gridLayout.addWidget( label3 , 0, 2 )
        # gridLayout.addWidget( label4 , 1, 0 )
        # gridLayout.addWidget( label5 , 1, 1 )
          
        # self.setLayout( gridLayout )        
# #-------添加水平布局
# #        hBoxLayout1.addWidget( label1 )
# #        hBoxLayout1.addWidget( label2 )
# #        hBoxLayout1.addWidget( label3 )
# #        hBoxLayout1.addWidget( label4 )
# #        hBoxLayout1.addWidget( label5 )
# #        
# #        self.setLayout( hBoxLayout1 )
 
# #---------添加垂直布局
# #        vBoxLayout = QtGui.QVBoxLayout()
# #        vBoxLayout.addWidget( label1 )
# #        vBoxLayout.addWidget( label2 )
# #        vBoxLayout.addWidget( label3 )
# #        vBoxLayout.addWidget( label4 )
# #        vBoxLayout.addWidget( label5 )
# #        
# #        self.setLayout( vBoxLayout )
# #        
 
 
# app = QtGui.QApplication( sys.argv )
# demo = Window()
# demo.show()
# app.exec_()



# #coding=utf-8
# #按钮操作
 
# import sys
# from PyQt4 import QtGui, QtCore
# class Window( QtGui.QWidget ):
    # def __init__( self ):
        # super( Window, self ).__init__()
        # self.setWindowTitle( "hello" )
        # self.resize( 500, 500 )
        # gridlayout = QtGui.QGridLayout()
         
        # button1 = QtGui.QPushButton( "button1" )
        # gridlayout.addWidget( button1, 0, 0, 1, 3 )
         
        # button2 = QtGui.QPushButton( "button2" )
        # button2.setFlat( True )
        # gridlayout.addWidget( button2, 1, 1, 1, 3 )
        # self.setLayout( gridlayout )
# app = QtGui.QApplication( sys.argv )
# demo = Window()
# demo.show()
# app.exec_()



# #coding=utf-8
# import sys
# from PyQt4 import QtGui, QtCore
# class Window( QtGui.QWidget ):
    # def __init__( self ):
        # super( Window, self ).__init__()
        # self.setWindowTitle( "hello" )
        # self.resize( 500, 500 )
         
        # gridlayout = QtGui.QGridLayout()
         
        # str = "hello"  #这里中文乱码，纠结
        # label = QtGui.QLabel( str )
        # label.setAlignment( QtCore.Qt.AlignCenter )
         
        # textFile = QtGui.QLineEdit()
        # gridlayout.addWidget( label, 0, 0 )
        # gridlayout.addWidget( textFile )
         
        # passwordFile = QtGui.QLineEdit()
        # passwordFile.setEchoMode( QtGui.QLineEdit.Password )
        # gridlayout.addWidget( passwordFile )
         
        # textArea = QtGui.QTextEdit()
        # textArea.setText( "asdasda" )
        # gridlayout.addWidget( textArea )
         
         
        # self.setLayout( gridlayout )
# app = QtGui.QApplication( sys.argv )
# window = Window()
# window.show()
# app.exec_()




# import sys
# from PyQt4 import QtGui, QtCore
# class Window( QtGui.QWidget ):
    # def __init__( self ):
        # super( Window, self ).__init__()
        # self.setWindowTitle( "hello" )
        # self.resize( 500, 500 )
        # hboxlayout = QtGui.QHBoxLayout()
         
        # self.radio1 = QtGui.QRadioButton( "radio1" )
        # self.radio2 = QtGui.QRadioButton( "radio2" )
        # self.radio3 = QtGui.QRadioButton( "radio3" )
        # self.radio1.setChecked( True )
         
        # hboxlayout.addWidget( self.radio1 )
        # hboxlayout.addWidget( self.radio2 )
        # hboxlayout.addWidget( self.radio3 )
         
        # checkbox1 = QtGui.QCheckBox( "checkbox1" )
        # checkbox2 = QtGui.QCheckBox( "checkbox2" )
        # checkbox3 = QtGui.QCheckBox( "checkbox3" )
        # checkbox1.setChecked( True )
         
        # hboxlayout.addWidget( checkbox1 )
        # hboxlayout.addWidget( checkbox2 )
        # hboxlayout.addWidget( checkbox3 )
 
        # self.button = QtGui.QPushButton( "Ok" )
        # hboxlayout.addWidget( self.button )
         
        # self.connect( self.button, QtCore.SIGNAL( 'clicked()' ), self.OnButton )
         
        # self.setLayout( hboxlayout )
    # def OnButton( self ):
        # if self.radio2.isChecked():
            # self.radio2.setText( "haha" )
         
# app = QtGui.QApplication( sys.argv )
# win = Window()
# win.show()
# app.exec_()



# #coding=utf-8
# #菜单事件
# import sys
# from PyQt4 import QtGui, QtCore
# class Window( QtGui.QMainWindow ):
    # def __init__( self ):
        # super( Window, self ).__init__()
        # self.setWindowTitle( "hello" )
        # self.resize( 500, 500 )
         
         
         
        # menubar = self.menuBar()
        # self.file = menubar.addMenu( '&File' )
        # open = self.file.addAction( 'Open' )
        # self.connect( open, QtCore.SIGNAL( 'triggered()' ), self.OnOpen )
         
        # save = self.file.addAction( 'Save' )
        # self.connect( save, QtCore.SIGNAL( 'triggered()' ), self.OnSave )
        # self.file.addSeparator()
        # close = self.file.addAction( "Close" )
        # self.connect( close, QtCore.SIGNAL( 'triggered()' ), self.OnClose )
         
        # self.label = QtGui.QLabel( "this is a  google test" )
        # self.label.setAlignment( QtCore.Qt.AlignCenter )
        # self.setCentralWidget( self.label )
         
    # def OnOpen( self ):
        # self.label.setText( "open" )
    # def OnSave( self ):
        # self.label.setText( "save" )
    # def OnClose( self ):
        # self.close()
    # def contextMenuEvent( self, event ):
       # self.file.exec_( event.globalPos() )
# app = QtGui.QApplication( sys.argv )
# win = Window()
# win.show()
# app.exec_()



#coding=utf-8
#对话框
import sys
from PyQt4 import QtGui, QtCore
class Window( QtGui.QWidget ):
    def __init__( self ):
        super( Window, self ).__init__()
        self.setWindowTitle( "hello" )
        self.resize( 500, 500 )
         
        gridlayout = QtGui.QGridLayout()
         
        self.AboutButton = QtGui.QPushButton( "About" )
        gridlayout.addWidget( self.AboutButton, 0, 0 )
        self.AboutQtButton = QtGui.QPushButton( "AboutQt" )
        gridlayout.addWidget( self.AboutQtButton, 0, 1 )
        self.CriticalButton = QtGui.QPushButton( "CriticalButton" )
        gridlayout.addWidget( self.CriticalButton, 1, 0 )
        self.InfoButton = QtGui.QPushButton( "Info" )
        gridlayout.addWidget( self.InfoButton, 1, 1 )
        self.QuestionButton = QtGui.QPushButton( "Question" )
        gridlayout.addWidget( self.QuestionButton, 2, 0 )
        self.WarningButton = QtGui.QPushButton( "Warning" )
        gridlayout.addWidget( self.WarningButton, 2, 1 )
         
        spacer = QtGui.QSpacerItem( 200, 80 )
        gridlayout.addItem( spacer, 3, 1, 1, 5 )
        self.setLayout( gridlayout )
         
        self.connect( self.AboutButton, QtCore.SIGNAL( 'clicked()' ), self.OnAboutButton )
        self.connect( self.AboutQtButton, QtCore.SIGNAL( 'clicked()' ), self.OnAboutQtButton )
        self.connect( self.CriticalButton, QtCore.SIGNAL( 'clicked()' ), self.OnCriticalButton )
        self.connect( self.InfoButton, QtCore.SIGNAL( 'clicked()' ), self.OnInfoButton )
        self.connect( self.QuestionButton, QtCore.SIGNAL( 'clicked()' ), self.OnQuestionButton )
        self.connect( self.WarningButton, QtCore.SIGNAL( 'clicked()' ), self.OnWarningButton )
         
    def OnAboutButton( self ):
        QtGui.QMessageBox.about( self, 'PyQt', "About" )
         
    def OnAboutQtButton( self ):
        QtGui.QMessageBox.aboutQt( self, "PyQt" )
         
    def OnCriticalButton( self ):
        r = QtGui.QMessageBox.critical( self, "PyQT", "CriticalButton", QtGui.QMessageBox.Abort,
                                   QtGui.QMessageBox.Retry, QtGui.QMessageBox.Ignore )
        if r == QtGui.QMessageBox.Abort:
            self.setWindowTitle( "Abort" )
        elif r == QtGui.QMessageBox.Retry:
            self.setWindowTitle( "Retry" )
        elif r == QtGui.QMessageBox.Ignore:
            self.setWindowTitle( "Ignore" )
        else:
            pass
         
    def OnInfoButton( self ):
        QtGui.QMessageBox.information( self, "Pyqt", "information" )
         
    def OnQuestionButton( self ):
        r = QtGui.QMessageBox.question( self, "PyQt", "Question", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No, QtGui.QMessageBox.Cancel )
         
    def OnWarningButton( self ):
        r = QtGui.QMessageBox.warning( self, "PyQT", "warning", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No )
     
         
app = QtGui.QApplication( sys.argv )
win = Window()
win.show()
app.exec_()